home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright Cornell University 1986. All rights are reserved.
-
- As of 4/10/86:
- This source file may have no changes from the M.I.T original
- other than this notice; but it has been tested as part of
- Cornell's Aztec-C port. See notice.h
-
- telnet.c contains the telnet layer of the application.
- It also contains file transfer routines.
-
- */
-
- #include <em.h>
-
- #include <cntldefs.h>
- #include <3270.h>
- #include <rcodes.h>
- #include "ft.h"
-
- #define TELDATA 0
- #define TELCOM 1
- #define TELWONT 2
- #define TELWILL 3
- #define TELDO 4
- #define TELDONT 5
- #define TELNEGO 6
- #define TELNEGO1 7
- #define TELNEGO2 8
- #define TELNEGO3 9
-
-
- char sb_termtype[] = {TNIAC, 0xfa, 0x18, 0x00};
- char *sb_term[] = {
- "VT100", /* officially a "DEC-VT100" but not by termcap...*/
- "IBM-3278-",
- "H19",
- "VT102"
- }; /* last entry repeated twice to indicate end of list */
- char sb_end[] = {TNIAC, 0xf0, 0x00};
-
- /* 3 types of ibm 3270 which might be reported; -4 is 43 X 80, not supported
- due to size >32 rows (modflg is a long bit-array, alas) */
- char ibm_types[] = {
- '2', /* 24 X 80 */
- '3', /* 32 X 80 */
- '5' /* 27 X 132 */
- };
-
- int hostconncomplete(); /* the host connect action completion call */
-
- wr_usr(buf, len, urg)
- unsigned char *buf;
- int len;
- int urg;
- {
- register unsigned int thechar;
- register unsigned char * bufend;
- register unsigned char * bufp;
- unsigned char *com_begin;
- int comcount;
- struct ucb *pucb;
-
- pucb = &emdp->ucb;
-
- bufend = buf + len;
- com_begin = NULL;
-
- for (bufp = buf; bufp < bufend; bufp++) {
- thechar = *bufp;
- if (emdp->telmode == TELDATA) {
- /* we eat up all data in this branch */
- if (thechar == TNIAC) {
- com_begin = NULL;
- emdp->telmode = TELCOM;
- }
- else {
- /* deal with most likely case: data */
-
- if (!emdp->tndata) {
- /* these are the first data bytes received */
- emdp->tndata = TRUE;
- if (!ibmtest())
- /* not 3270, guarantee terminal set to appropriate ASCII type */
- settermtype(emdp->termtype);
- if (!hostconncomplete(emdp->connmacro))
- termwake(); /* make sure controls drawn */
- }
-
- if (emdp->icon_up)
- emalert(); /* highlight icon to show activity */
-
- com_begin = bufp;
- for ( ; bufp < bufend && *bufp != TNIAC; bufp++) {
- /* find the next IAC or end of buffer */
- if (!emdp->tnbinary)
- /* mash the high bit down if not in binary mode */
- *bufp &= 0x7f;
- ;
- }
- comcount = bufp - com_begin;
-
- if (emdp->ibm_mode) {
- /* call the 3270 command processor w/the data */
- if (emdp->event_reg & TFTP_ON)
- tnftsave(com_begin, comcount);
- else
- cmd(com_begin, comcount);
- }
- else {
- (*emdp->emstr)(com_begin, comcount);
- emdp->hycnewdata = TRUE;
- }
-
- if (bufp < bufend) {
- /* found IAC */
- emdp->telmode = TELCOM;
- }
- else
- break;
- }
- }
- else {
- switch (emdp->telmode) {
- case TELCOM: {
- switch (thechar) {
- case TNEOR: {
- if (emdp->ibm_mode) {
- /* EOR signals 3270 end of record */
- if (emdp->event_reg & TFTP_ON) {
- tnftcomplete();
- }
- else {
- cmdcomplete();
- emdp->hycnewdata = TRUE;
- /* (*emdp->screen_upd)();
- delay to enhance performance when
- doing LIST etc which send screen as
- up to 10 separate packets....*/
- }
- }
- emdp->telmode = TELDATA;
- break;
- }
- case TNDO: {
- emdp->telmode = TELDO;
- break;
- }
- case TNDONT: {
- /* DONT */
- emdp->telmode = TELDONT;
- break;
- }
- case TNWILL: {
- emdp->telmode = TELWILL;
- break;
- }
- case TNWONT: {
- emdp->telmode = TELWONT;
- break;
- }
- case TNSB: {
- /* sub negotiation */
- emdp->telmode = TELNEGO;
- emdp->subnegofail = FALSE;
-